﻿using System;
using System.Collections.Generic;
using System.Web;

namespace FDeal
{
    public class DonHangBUS
    {
        private DonHangDAO _dDAO;

        public DonHangBUS()
        {
            _dDAO = new DonHangDAO();
        }

        public void Insert(DonHangDTO obj)
        {
            _dDAO.insert(obj);
        }

        public void Insert(string iddonhang, string idthanhtoan, string diachinhan, string duong,
            string tinhthanh, string quanhuyen, string idsanpham, int soluong,
            float tonggi, string hinhthucnhanhang)
        {
            DonHangDTO obj = new DonHangDTO();

            obj.Iddonhang = iddonhang;
            obj.Idthanhtoan = idthanhtoan;
            obj.Diachinhan = diachinhan;
            obj.Duong = duong;
            obj.Tinhthanh = tinhthanh;
            obj.Quanhuyen = quanhuyen;
            obj.Idsanpham = idsanpham;
            obj.Soluong = soluong;
            obj.Tonggia = tonggi;
            obj.Hinhthucnhanhang = hinhthucnhanhang;

            this.Insert(obj);
        }

        public void Delete(string idDeal)
        {
            _dDAO.delete(idDeal);
        }

        public void Update(DonHangDTO obj)
        {
            _dDAO.update(obj);
        }

        public DonHangDTO[] DetDsDonHang()
        {
            return _dDAO.getDsDonHang();
        }

        public DonHangDTO GetDonHang(string idDonHang)
        {
            DonHangDTO[] ds = this.DetDsDonHang();

            for (int i = 0; i < ds.Length; i++)
            {
                if (ds[i].Iddonhang.Equals(idDonHang))
                    return ds[i];
            }
            return null;
        }
    }
}